import React from 'react';
import { useAuth } from '@/hooks/useAuth';

interface PermissionButtonProps {
  permissions: string[];
  children: React.ReactNode;
}

const PermissionButton: React.FC<PermissionButtonProps> = ({ permissions, children }) => {
  const { userInfo } = useAuth();

  if (!userInfo || !userInfo.perms) {
    return null;
  }

  const hasPermission = permissions.some(perm => userInfo.perms.includes(perm));

  return hasPermission ? <>{children}</> : null;
};

export default PermissionButton;

// 使用
{/* <PermissionButton permissions={['user:add']}>
<Button type="primary">添加用户</Button>
</PermissionButton> */}
